package cn.xdd.servlet.poweManage;

import cn.xdd.dao.UserDao;
import cn.xdd.entity.User;
import org.apache.log4j.Logger;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author user_xdd
 * @Date 2022-04-01 16:05
 * @description 模拟上一层servlet传递一个user对象gettoKengetServleet
 * @return
 */
@WebServlet(urlPatterns = {"/lastSevlet"})
public class lastSevlet extends GenericServlet {
        private static  final Logger LOGGER = Logger.getLogger(lastSevlet.class);
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request  = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        request.setCharacterEncoding("utf-8");//设置请求中文编码
        response.setContentType("text/html;charset=utf-8");//设置响应中文编码


        UserDao userDao = new UserDao();
        try {
            User user = userDao.GetUserById(4);
            request.getSession().setAttribute("user",user);
             LOGGER.debug("    user:"+user);
            request.getRequestDispatcher("/TokenGetServlet").forward(request,response);
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
